import axios from 'axios'
import Router from '@/router'

//全局设置
const service = axios.create({
  baseURL: "http://localhost:8080", 
  timeout: 5000 
})

// 请求拦截器
service.interceptors.request.use(
  config => {
    //全局设置请求头
    config.headers.token = localStorage.getItem("token");
    return config
  }
)

//响应拦截器
service.interceptors.response.use(
  response => {
    const res = response.data
    
    if(res.code == "403"){
        //重定向到403路由
        Router.push({path:"/403"})
    }



    return res;
  }
)

export default service
